# CROSS COMPILER SETTING
SET(CMAKE_SYSTEM_NAME Generic)
CMAKE_MINIMUM_REQUIRED (VERSION 3.10.0)

# THE VERSION NUMBER
SET (Tutorial_VERSION_MAJOR 1)
SET (Tutorial_VERSION_MINOR 0)

# set toolchain
set(CMAKE_TOOLCHAIN_FILE "./armgcc/armgcc.cmake")

# ENABLE ASM
ENABLE_LANGUAGE(ASM)

set(CMAKE_STATIC_LIBRARY_PREFIX)
set(CMAKE_STATIC_LIBRARY_SUFFIX)

set(CMAKE_EXECUTABLE_LIBRARY_PREFIX)
set(CMAKE_EXECUTABLE_LIBRARY_SUFFIX)

# build type
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  message("Setting build type to 'debug' as none was specified.")
  set(CMAKE_BUILD_TYPE sdram_debug CACHE STRING "Choose the type of build." FORCE)
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "debug" "release"
    "flexspi_nor_debug" "flexspi_nor_release")
endif()


# CURRENT DIRECTORY
set(ProjDirPath ${CMAKE_CURRENT_SOURCE_DIR})

# LINKSCRIT DIR
set(ProjLinkPath "${ProjDirPath}/linkscripts")

# SET(EXECUTABLE_OUTPUT_PATH ${ProjDirPath}/${CMAKE_BUILD_TYPE})
# SET(LIBRARY_OUTPUT_PATH ${ProjDirPath}/${CMAKE_BUILD_TYPE})
set(CMAKE_EXPORT_COMPILE_COMMANDS True)


project(hello_world)

set(MCUX_SDK_PROJECT_NAME demo.elf)

include(${ProjDirPath}/armgcc/flags.cmake)

include(${ProjDirPath}/armgcc/config.cmake)

add_executable(${MCUX_SDK_PROJECT_NAME} 
"${ProjDirPath}/hello_world.c"
"${ProjDirPath}/board/pin_mux.c"
"${ProjDirPath}/board.c"
"${ProjDirPath}/clock_config.c"
"${ProjDirPath}/dcd.c"
)

target_include_directories(${MCUX_SDK_PROJECT_NAME} PRIVATE
    "${ProjDirPath}/board"
    "${ProjDirPath}"
)

set(SDKDirPath "/home/rensuiyi/wk/proj/nuttxos/resource/SDK_2_10_1_MIMXRT1062xxxxA")

set(CMAKE_MODULE_PATH
    ${SDKDirPath}/devices/MIMXRT1062/utilities/debug_console_lite
    ${SDKDirPath}/devices/MIMXRT1062/drivers
    ${SDKDirPath}/devices/MIMXRT1062
    ${SDKDirPath}/components/uart
    ${SDKDirPath}/components/lists
    ${SDKDirPath}/devices/MIMXRT1062/xip
    ${SDKDirPath}/boards/evkmimxrt1060/xip
    ${SDKDirPath}/CMSIS/Core/Include
    ${SDKDirPath}/devices/MIMXRT1062/utilities
)

# include modules
include(utility_debug_console_lite_MIMXRT1062)

include(utility_assert_lite_MIMXRT1062)

include(driver_clock_MIMXRT1062)

include(driver_common_MIMXRT1062)

include(device_MIMXRT1062_CMSIS_MIMXRT1062)

include(component_lpuart_adapter_MIMXRT1062)

include(component_lists_MIMXRT1062)

include(driver_lpuart_MIMXRT1062)

include(device_MIMXRT1062_startup_MIMXRT1062)

include(driver_iomuxc_MIMXRT1062)

include(driver_igpio_MIMXRT1062)

include(driver_xip_device_MIMXRT1062)

include(driver_xip_board_evkmimxrt1060_MIMXRT1062)

include(CMSIS_Include_core_cm_MIMXRT1062)

include(utilities_misc_utilities_MIMXRT1062)

include(device_MIMXRT1062_system_MIMXRT1062)


target_link_libraries(${MCUX_SDK_PROJECT_NAME} PRIVATE -Wl,--start-group)

target_link_libraries(${MCUX_SDK_PROJECT_NAME} PRIVATE m)

target_link_libraries(${MCUX_SDK_PROJECT_NAME} PRIVATE c)

target_link_libraries(${MCUX_SDK_PROJECT_NAME} PRIVATE gcc)

target_link_libraries(${MCUX_SDK_PROJECT_NAME} PRIVATE nosys)

target_link_libraries(${MCUX_SDK_PROJECT_NAME} PRIVATE -Wl,--end-group)


ADD_CUSTOM_COMMAND(TARGET ${MCUX_SDK_PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_OBJCOPY} ARGS -Oihex ${MCUX_SDK_PROJECT_NAME} ${MCUX_SDK_PROJECT_NAME}.hex)
ADD_CUSTOM_COMMAND(TARGET ${MCUX_SDK_PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_OBJCOPY} ARGS -Obinary ${MCUX_SDK_PROJECT_NAME} ${MCUX_SDK_PROJECT_NAME}.bin)